using System;
using System.Windows;
using MaxAlarm.Common;

namespace MaxAlarm.Core.Settings
{
    public class SettingsManager : DependencyObject
    {
        #region Singletone
        private static readonly object Locker = new object();
        private static SettingsManager _instance;

        public static SettingsManager Instance
        {
            get
            {
                lock (Locker)
                {
                    return _instance ?? (_instance = new SettingsManager());
                }
            }
        }

        private SettingsManager()
        {
            
        }

        #endregion

        public event EventHandler Initialized;

        public static readonly DependencyProperty SettingsProperty =
            DependencyProperty.Register("Settings", typeof (MaxAlarmSettings), typeof (SettingsManager), new PropertyMetadata(null));

        public MaxAlarmSettings Settings
        {
            get { return this.SafeGetValue<MaxAlarmSettings>(SettingsProperty); }
            set { this.SafeSetValue(SettingsProperty, value); }
        }

        private readonly SettingsProvider _provider = new SettingsProvider();

        public void Initialize()
        {
            Settings = _provider.GetSettings();

            if (Initialized != null)
                Initialized(this, EventArgs.Empty);
        }


        public void SaveSetting()
        {
            _provider.SaveSettings(Settings);
        }

    }
}
